class Assign < ActiveRecord::Base
  belongs_to :example
  belongs_to :dictionary
  
  def self.make_for(ids)
    raise "Format Error: ids should be Array class or Fixnum class" if ids.any?{|id| id.class != Fixnum }
    
    condition = ids.join(",")
    sql = 
    "CREATE TEMPORARY TABLE temporary_assigns AS " +
    "SELECT * FROM assigns " +
    "WHERE assigns.example_id IN ("+
      "SELECT assigns.example_id FROM assigns "+
      "WHERE assigns.dictionary_id IN (#{condition}) "+
      "GROUP BY assigns.example_id);"
    self.connection.execute sql
  end
  
  def self.drop_temporary
    self.connection.drop_table :temporary_assigns
  end
end
